#include <cpcap-device-enumerator.hpp>
#include <devices.hpp>
#include <stdlib.h>
#include <common.hpp>

CPCapDeviceEnumerator::CPCapDeviceEnumerator() :
    First(NULL),
    Current(NULL)
{
    capture_device_info_t *info  = NULL;
    int                   status = 0;

    info = list_capture_devices(&status);
    if (status != OK_STATUS)
        capture_device_info_free(info);

    First = info;
}

CPCapDeviceEnumerator::~CPCapDeviceEnumerator()
{
    if (First)
        capture_device_info_free(First);
}

bool
CPCapDeviceEnumerator::next()
{
    if (!Current)
        Current = First;
    else
        Current = Current->next;

    return (Current != NULL);
}

bool
CPCapDeviceEnumerator::first()
{
    Current = First;

    return (Current != NULL);
}

const char *
CPCapDeviceEnumerator::name() const
{
    if (Current)
        return const_cast<const char *>(Current->name);
    else
        return NULL;
}

const char *
CPCapDeviceEnumerator::uid() const
{
    if (Current)
        return const_cast<const char *>(Current->uid);
    else
        return NULL;
}
